package com.liuzy.test;

import org.springframework.core.io.FileSystemResource;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;

public class BlockFileSystemResource extends FileSystemResource {
    private final Block block;

    public BlockFileSystemResource(Block block) {
        super(block.getSrc());
        this.block = block;
    }

    @Override
    public InputStream getInputStream() throws IOException {
        return new ByteArrayInputStream(block.getBlockBytes());
    }

    @Override
    public long contentLength() throws IOException {
        return block.getLength() - block.getOffset();
    }

    @Override
    public String getFilename() {
        return this.block.toName();
    }
}
